package com.example.a22310.myapplication.ViewModel.Club;

import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.widget.Toast;

import com.example.a22310.myapplication.Adapter.MvvmAdapter;
import com.example.a22310.myapplication.Beans.Club;
import com.example.a22310.myapplication.Listener.ClubListener;
import com.example.a22310.myapplication.Model.ClubModel;
import com.example.a22310.myapplication.R;

import java.util.List;

public class ClubViewModel implements ClubListener<Club> {
    private FragmentPeopleBinding fragmentPeopleBinding;
    private FragmentActivity activity;


    public ClubViewModel(FragmentActivity activity, FragmentPeopleBinding fragmentPeopleBinding){
        this.activity = activity;
        this.fragmentPeopleBinding = fragmentPeopleBinding;
        fragmentPeopleBinding.setClub(this);
        ClubModel clubModel=new ClubModel();
        clubModel.clubList(ClubViewModel.this);
    }



    @Override
    public void onSuccess(Club club) {
        if(club.getCode()!=404){
            List<Club.ClublistBean> clublistBean =  club.getClublist();
            fragmentPeopleBinding.recyclerViewClub.setLayoutManager(
                    new LinearLayoutManager(activity));
            MvvmAdapter adapter = new MvvmAdapter(activity, R.layout.cardview_club,
                    clublistBean, BR.club);
            fragmentPeopleBinding.recyclerViewClub.setAdapter(adapter);
        }

    }

    @Override
    public void onFailure() {
        Toast.makeText(activity,"连接服务器失败",Toast.LENGTH_LONG).show();
    }

}
